package com.freewater.springboot.demo.ioc.qualifier.useannotation;

import com.freewater.springboot.demo.ioc.qualifier.MovieCatalog;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 *
 * Trying to inject the results from @Bean methods on the same configuration class is effectively a self-reference scenario as well.
 * Either lazily resolve such references in the method signature where it is actually needed (as opposed to an autowired field in the configuration class)
 * or declare the affected @Bean methods as static, decoupling them from the containing configuration class instance and its lifecycle.
 * Otherwise, such beans are only considered in the fallback phase, with matching beans on other configuration classes selected as primary candidates instead (if available).
 */
@Import(ComponentConfig.class)
@Configuration
@Getter
public class AppConfig {

    /**
     * Trying to inject the results from @Bean methods on the same configuration class is effectively a self-reference scenario as well.
     * 自动注入当前Configuration类中Bean方法返回的bean属于自引用注入
     */
    @Autowired
    private MovieCatalog movieCatalog; // 会注入movieCatalog2

    @Bean
    public MovieCatalog movieCatalog1() {
        return new MovieCatalog();
    }
}
